package com.app.components
{
	import com.app.base.Component;
	import com.app.events.ControlEvent;
	
	public class Button extends Component
	{
		public function Button()
		{
			super();
			this.addEventListener(ControlEvent.DOWN ,controlHandler);
			Global.eventDispatcher.addEventListener(ControlEvent.DRAG_START ,controlHandler);
		}
		
		private function controlHandler(event:ControlEvent):void
		{
			switch(event.type)
			{
				case ControlEvent.DOWN:
					this.parent.addEventListener(ControlEvent.UP ,controlHandler);
					gotoAndStop(2);
					return;
					
				case ControlEvent.UP:case ControlEvent.DRAG_START:
					hide();
					return;
			}
		}
		
		private function hide():void
		{
			this.parent..removeEventListener(ControlEvent.UP ,controlHandler);
			gotoAndStop(1);
		}
	}
}